<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
<!--      <el-form-item label="员工名称" prop="peopleName">-->
<!--        <el-input-->
<!--          v-model="queryParams.peopleName"-->
<!--          placeholder="请输入员工名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="员工编号" prop="peopleCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.peopleCode"-->
<!--          placeholder="请输入员工编号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="员工证件号" prop="peopleCardNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.peopleCardNum"-->
<!--          placeholder="请输入员工证件号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="客户企业" prop="companyName">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyName"-->
<!--          placeholder="请输入客户企业"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="签约主体" prop="signMainName">-->
<!--        <el-input-->
<!--          v-model="queryParams.signMainName"-->
<!--          placeholder="请输入签约主体"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <!--      <el-form-item label="日期" prop="reportDate">-->
      <!--        <el-date-picker clearable-->
      <!--                        v-model="queryParams.reportDate"-->
      <!--                        type="date"-->
      <!--                        value-format="yyyy-MM-dd"-->
      <!--                        placeholder="请选择日期">-->
      <!--        </el-date-picker>-->
      <!--      </el-form-item>-->
<!--      <el-form-item label="社保账户" prop="socialSecurityNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.socialSecurityNum"-->
<!--          placeholder="请输入社保账户"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <!--      <el-form-item label="社保档位" prop="ssLevel">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ssLevel"-->
      <!--          placeholder="请输入社保档位"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="社保基数" prop="ssBase">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ssBase"-->
      <!--          placeholder="请输入社保基数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="社保补缴月数" prop="ssSupplementMonthNum">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ssSupplementMonthNum"-->
      <!--          placeholder="请输入社保补缴月数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="社保补缴基数" prop="ssSupplementBase">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ssSupplementBase"-->
      <!--          placeholder="请输入社保补缴基数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="社保申报月份" prop="ssReportMonth">
        <el-date-picker clearable
                        v-model="queryParams.ssReportMonth"
                        type="month"
                        value-format="yyyy-MM"
                        placeholder="请选择社保申报月份">
        </el-date-picker>
      </el-form-item>
      <!--      <el-form-item label="社保生效月份" prop="ssEffectMonth">-->
      <!--        <el-date-picker clearable-->
      <!--                        v-model="queryParams.ssEffectMonth"-->
      <!--                        type="date"-->
      <!--                        value-format="yyyy-MM-dd"-->
      <!--                        placeholder="请选择社保生效月份">-->
      <!--        </el-date-picker>-->
      <!--      </el-form-item>-->
<!--      <el-form-item label="公积金账户" prop="fundNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.fundNum"-->
<!--          placeholder="请输入公积金账户"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <!--      <el-form-item label="公积金档位" prop="afLevel">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.afLevel"-->
      <!--          placeholder="请输入公积金档位"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="公积金基数" prop="afBase">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.afBase"-->
      <!--          placeholder="请输入公积金基数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="公积金补缴月数" prop="afSupplementMonthNum">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.afSupplementMonthNum"-->
      <!--          placeholder="请输入公积金补缴月数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="公积金补缴基数" prop="afSupplementBase">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.afSupplementBase"-->
      <!--          placeholder="请输入公积金补缴基数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="公积金申报月份" prop="afReportMonth">
        <el-date-picker clearable
                        v-model="queryParams.afReportMonth"
                        type="month"
                        value-format="yyyy-MM"
                        placeholder="请选择公积金申报月份">
        </el-date-picker>
      </el-form-item>
      <!--      <el-form-item label="公积金生效月份" prop="afEffectMonth">-->
      <!--        <el-date-picker clearable-->
      <!--                        v-model="queryParams.afEffectMonth"-->
      <!--                        type="date"-->
      <!--                        value-format="yyyy-MM-dd"-->
      <!--                        placeholder="请选择公积金生效月份">-->
      <!--        </el-date-picker>-->
      <!--      </el-form-item>-->
            <el-form-item label="办理类型" prop="type">
              <el-select v-model="queryParams.type" placeholder="请选择办理类型" clearable filterable>
                <el-option
                  v-for="item in dict.type.people_ssaf_report_handle_item"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
      <!--      <el-form-item label="状态" prop="status">-->
      <!--        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable filterable>-->
      <!--          <el-option-->
      <!--            v-for="item in dict.type.people_ssaf_report_status"-->
      <!--            :key="item.value"-->
      <!--            :label="item.label"-->
      <!--            :value="item.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          plain-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="handleAdd"-->
      <!--          v-hasPermi="['peopleSsafReport:peopleSsafReport:add']"-->
      <!--        >新增-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="success"-->
      <!--          plain-->
      <!--          icon="el-icon-edit"-->
      <!--          size="mini"-->
      <!--          :disabled="single"-->
      <!--          @click="handleUpdate"-->
      <!--          v-hasPermi="['peopleSsafReport:peopleSsafReport:edit']"-->
      <!--        >修改-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="el-icon-delete"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          v-hasPermi="['peopleSsafReport:peopleSsafReport:remove']"-->
      <!--        >删除-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="info"-->
      <!--          plain-->
      <!--          icon="el-icon-upload2"-->
      <!--          size="mini"-->
      <!--          @click="handleImport"-->
      <!--          v-hasPermi="['peopleSsafReport:peopleSsafReport:import']"-->
      <!--        >导入-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['peopleSsafReport:peopleSsafReport:export']"
        >导出
        </el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-check"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['peopleSsafReport:peopleSsafReport:submit']"-->
<!--        >批量提交至【待申报】-->
<!--        </el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" type="index" width="50" align="center" fixed="left" />
      <!--      <el-table-column label="ID" align="center" prop="id"/>-->
      <el-table-column label="员工名称" align="center" prop="people.name" fixed="left" />
      <el-table-column label="员工编号" align="center" prop="people.code" width="100" fixed="left" />
      <el-table-column label="证件号码" align="center" prop="people.cardNum" width="100" fixed="left" />
      <el-table-column label="客户企业" align="center" prop="company.nameSecond" width="100" fixed="left" />
      <el-table-column label="签约主体" align="center" prop="signMain.name" width="100" fixed="left" />
      <el-table-column label="户籍类型" align="center" prop="people.domicileType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.domicile_type" :value="scope.row.people.domicileType"/>
        </template>
      </el-table-column>
      <el-table-column label="电话号码" align="center" prop="people.mobilePhone"/>
      <el-table-column label="开户行" align="center" prop="people.bank"/>
      <el-table-column label="银行账号" align="center" prop="people.bankNum"/>
      <el-table-column label="民族" align="center" prop="people.nation"/>
      <el-table-column label="学历" align="center" prop="people.education">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.education" :value="scope.row.people.education"/>
        </template>
      </el-table-column>
      <el-table-column label="婚育状况" align="center" prop="people.marital">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.marital_status" :value="scope.row.people.marital"/>
        </template>
      </el-table-column>

<!--      <el-table-column label="日期" align="center" prop="reportDate" width="120">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.reportDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="社保办理险种" align="center" prop="handleInsuranceType" width="100"
                       :formatter="handleInsuranceTypeFormat"/>
      <el-table-column label="社保账户" align="center" prop="people.socialSecurityNum"/>
      <el-table-column label="社保缴费比例" align="center" prop="signMain.yangLaoPayProportionEtp" width="210">
        <template slot-scope="scope">
          <span>养老：企业{{ scope.row.signMain.yangLaoPayProportionEtp }}%，个人{{ scope.row.signMain.yangLaoPayProportionPsn }}%；
            医疗：企业{{ scope.row.signMain.yiLiaoPayProportionEtp }}%，个人{{ scope.row.signMain.yiLiaoPayProportionPsn }}%；
            失业：企业{{ scope.row.signMain.shiYePayProportionEtp }}%，个人{{ scope.row.signMain.shiYePayProportionPsn }}%；
            工伤：{{ scope.row.signMain.gongShangPayProportionEtp }}%；生育：{{ scope.row.signMain.shengYuPayProportionEtp }}%；
          </span>
        </template>
      </el-table-column>
      <el-table-column label="社保基数" align="center" prop="ssBase"/>
      <el-table-column label="社保补缴月数" align="center" prop="ssSupplementMonthNum" width="100"/>
      <el-table-column label="社保补缴基数" align="center" prop="ssSupplementBase" width="100"/>
      <el-table-column label="社保申报月份" align="center" prop="ssReportMonth" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ssReportMonth, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="社保生效月份" align="center" prop="ssEffectMonth" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ssEffectMonth, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公积金账户" align="center" prop="people.fundNum" width="100"/>
      <el-table-column label="公积金缴费比例" align="center" prop="signMain.afPayProportionEtp" width="150">
        <template slot-scope="scope">
          <span>企业{{ scope.row.signMain.afPayProportionEtp }}%，个人{{ scope.row.signMain.afPayProportionPsn }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="公积金基数" align="center" prop="afBase" width="100"/>
      <el-table-column label="公积金补缴月数" align="center" prop="afSupplementMonthNum" width="120"/>
      <el-table-column label="公积金补缴基数" align="center" prop="afSupplementBase" width="120"/>
      <el-table-column label="公积金申报月份" align="center" prop="afReportMonth" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.afReportMonth, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公积金生效月份" align="center" prop="afEffectMonth" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.afEffectMonth, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="缴纳所在省" align="center" prop="payProvinceName" width="100"/>
      <el-table-column label="缴纳所在市" align="center" prop="payCityName" width="100"/>
      <el-table-column label="减员原因" align="center" prop="reason"/>
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.people_ssaf_report_handle_item" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.people_ssaf_report_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="130" fixed="right">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['peopleSsafReport:peopleSsafReport:edit']"-->
<!--          >修改-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-check"-->
<!--            @click="handleSubmit(scope.row)"-->
<!--            v-hasPermi="['peopleSsafReport:peopleSsafReport:submit']"-->
<!--          >提交至【待申报】-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['peopleSsafReport:peopleSsafReport:remove']"-->
<!--          >删除-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改员工社保公积金申报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">

        <el-form-item label="员工编号" prop="peopleCode">
          <el-input v-model="form.peopleCode" placeholder="请输入员工编号" @change="queryPeopleByCode" style="width: 400px"/>
        </el-form-item>
        <el-form-item label="员工姓名" prop="peopleName">
          <el-input v-model="form.peopleName" placeholder="" :disabled="true" style="width: 400px"/>
        </el-form-item>
        <el-form-item label="所属客户企业" prop="companyNameSecond">
          <el-input v-model="form.companyNameSecond" placeholder="" :disabled="true" style="width: 400px"/>
        </el-form-item>
        <el-form-item label="社保缴费比例" prop="ssPayProportion">
          <el-input v-model="form.ssPayProportion" placeholder="" :disabled="true" style="width: 400px"/>
        </el-form-item>
        <el-form-item label="公积金缴费比例" prop="afPayProportion">
          <el-input v-model="form.afPayProportion" placeholder="" :disabled="true" style="width: 400px"/>
        </el-form-item>

        <el-form-item label="日期" prop="reportDate">
          <el-date-picker clearable
                          style="width: 400px"
                          v-model="form.reportDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="社公办理类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择社公办理类型" style="width: 400px">
            <el-option
              v-for="dict in dict.type.people_ssaf_report_handle_item"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="社保账户" prop="ssAccount">
          <el-input v-model="form.ssAccount" placeholder="请输入社保账户" style="width: 400px"/>
        </el-form-item>
        <!--        <el-form-item label="社保档位" prop="ssLevel">-->
        <!--          <el-input v-model="form.ssLevel" placeholder="请输入社保档位" />-->
        <!--        </el-form-item>-->
        <el-form-item label="社保基数" prop="ssBase">
          <el-input v-model="form.ssBase" placeholder="请输入社保基数"
                    onkeyup="this.value= this.value.match(/\d/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                    style="width: 400px"/>
        </el-form-item>
        <el-form-item label="社保补缴月数" prop="ssSupplementMonthNum">
          <el-input v-model="form.ssSupplementMonthNum" placeholder="请输入社保补缴月数" @input="validateSsMonthNum" style="width: 400px"/>
        </el-form-item>
        <el-form-item label="社保补缴基数" prop="ssSupplementBase">
          <el-input v-model="form.ssSupplementBase" placeholder="请输入社保补缴基数"
                    onkeyup="this.value= this.value.match(/\d/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                    style="width: 400px"/>
        </el-form-item>
        <el-form-item label="社保申报月份" prop="ssReportMonth">
          <el-date-picker clearable
                          style="width: 400px"
                          v-model="form.ssReportMonth"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择社保申报月份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="社保生效月份" prop="ssEffectMonth">
          <el-date-picker clearable
                          style="width: 400px"
                          v-model="form.ssEffectMonth"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择社保生效月份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公积金账户" prop="afAccount">
          <el-input v-model="form.afAccount" placeholder="请输入公积金账户" style="width: 400px"/>
        </el-form-item>
        <!--        <el-form-item label="公积金档位" prop="afLevel">-->
        <!--          <el-input v-model="form.afLevel" placeholder="请输入公积金档位" />-->
        <!--        </el-form-item>-->
        <el-form-item label="公积金基数" prop="afBase">
          <el-input v-model="form.afBase" placeholder="请输入公积金基数"
                    onkeyup="this.value= this.value.match(/\d/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                    style="width: 400px"/>
        </el-form-item>
        <el-form-item label="公积金补缴月数" prop="afSupplementMonthNum">
          <el-input v-model="form.afSupplementMonthNum" placeholder="请输入公积金补缴月数" @input="validateAfMonthNum"
                    style="width: 400px"/>
        </el-form-item>
        <el-form-item label="公积金补缴基数" prop="afSupplementBase">
          <el-input v-model="form.afSupplementBase" placeholder="请输入公积金补缴基数"
                    onkeyup="this.value= this.value.match(/\d/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
                    style="width: 400px"/>
        </el-form-item>
        <el-form-item label="公积金申报月份" prop="afReportMonth">
          <el-date-picker clearable
                          style="width: 400px"
                          v-model="form.afReportMonth"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择公积金申报月份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公积金生效月份" prop="afEffectMonth">
          <el-date-picker clearable
                          style="width: 400px"
                          v-model="form.afEffectMonth"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择公积金生效月份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="缴纳所在省" prop="payProvinceCode">
          <el-select v-model="form.payProvinceCode" placeholder="请选择省级地区" @change="getCity">
            <el-option
              v-for="dict in provinceOptions"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="缴纳所在市" prop="payCityCode">
          <el-select v-model="form.payCityCode" placeholder="请选择市级地区" >
            <el-option
              v-for="dict in cityOptions"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公积金生效月份" prop="afEffectMonth">
          <el-date-picker clearable
                          style="width: 400px"
                          v-model="form.afEffectMonth"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择公积金生效月份">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="减员原因" prop="reason">
          <el-input v-model="form.reason" type="textarea" placeholder="请输入减员原因" style="width: 400px"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--上传对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--          <div class="el-upload__tip" slot="tip">-->
          <!--            <el-checkbox v-model="upload.updateSupport"/>-->
          <!--            是否更新已经存在的本次申报的员工数据-->
          <!--          </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPeopleSsafReport,
  getPeopleSsafReport,
  delPeopleSsafReport,
  addPeopleSsafReport,
  updatePeopleSsafReport, submitToReport
} from "@/api/people_ssaf_report/peoplessafreport";
import {queryByCode} from "@/api/people/people";
import {getChildrenById} from "@/api/system/area";
import {getToken} from "@/utils/auth";


export default {
  name: "stopProtect",
  dicts: ['ss_handle_type', 'people_ssaf_report_status','education','domicile_type','marital_status','people_ssaf_report_handle_item'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工社保公积金申报表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        orderByColumn : "m.id",
        isAsc:"desc",
        pageNum: 1,
        pageSize: 10,
        peopleId: null,
        type: null,
        status: null,
        reportDate: null,
        handleInsuranceType: null,
        ssAccount: null,
        ssLevel: null,
        ssBase: null,
        ssSupplementMonthNum: null,
        ssSupplementBase: null,
        ssReportMonth: null,
        ssEffectMonth: null,
        afAccount: null,
        afLevel: null,
        afBase: null,
        afSupplementMonthNum: null,
        afSupplementBase: null,
        afReportMonth: null,
        afEffectMonth: null,
        reason: null,
        peopleCardNum: null,
        peopleName: null,
        peopleCode: null,
        companyName: null,
        signMainName: null,
        socialSecurityNum :null,
        fundNum:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

        peopleCode: [
          {required: true, message: "请输入员工编号", trigger: "blur"}
        ],
        payProvinceCode: [
          {required: true, message: "请选择缴纳所在省", trigger: "change"}
        ],
        payCityCode: [
          {required: true, message: "请选择缴纳所在市", trigger: "change"}
        ],

      },
      provinceOptions:[],
      cityOptions:[],
      upload: {
        // 是否显示弹出层（投保方案导入）
        open: false,
        // 弹出层标题（投保方案导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的投保方案数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/peopleSsafReport/peopleSsafReport/importData"
      },
    };
  },
  created() {
    // this.getProvince();
    var peopleId = this.$route.query.peopleId;
    if ( peopleId ){
      this.queryParams.peopleId = peopleId;
    }
    this.getList();
  },
  methods: {
    /** 查询员工社保公积金申报列表 */
    getList() {
      this.loading = true;
      // this.queryParams.type = "2";
      // this.queryParams.status = "4";
      if (this.queryParams.ssReportMonth && this.queryParams.ssReportMonth.length === 7){
        this.queryParams.ssReportMonth = this.queryParams.ssReportMonth + '-01';
      }
      if (this.queryParams.afReportMonth && this.queryParams.afReportMonth.length === 7){
        this.queryParams.afReportMonth = this.queryParams.afReportMonth + '-01';
      }
      listPeopleSsafReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        peopleId: null,
        type: null,
        status: null,
        reportDate: null,
        handleInsuranceType: null,
        ssAccount: null,
        ssLevel: null,
        ssBase: null,
        ssSupplementMonthNum: null,
        ssSupplementBase: null,
        ssReportMonth: null,
        ssEffectMonth: null,
        afAccount: null,
        afLevel: null,
        afBase: null,
        afSupplementMonthNum: null,
        afSupplementBase: null,
        afReportMonth: null,
        afEffectMonth: null,
        reason: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        peopleCode: null,
        peopleName: null,
        companyNameSecond: null,
        ssPayProportion: null,
        afPayProportion: null,
        payCityCode:null,
        payProvinceCode:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加员工社保公积金申报";

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPeopleSsafReport(id).then(response => {
        this.form = response.data;
        this.form.peopleCode = response.data.people.code;
        this.queryPeopleByCode(this.form.peopleCode);
        this.getCity(this.form.payProvinceCode);
        this.open = true;
        this.title = "修改员工社保公积金申报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.peopleId == null) {
            this.$message.error("请正确输入员工编号")
            return false;
          }
          if(this.form.ssReportMonth){
            this.form.ssReportMonth = this.form.ssReportMonth +'-01';
          }
          if (this.form.ssEffectMonth){
            this.form.ssEffectMonth = this.form.ssEffectMonth +'-01';
          }
          if(this.form.afReportMonth){
            this.form.afReportMonth = this.form.afReportMonth +'-01';
          }
          if (this.form.afEffectMonth){
            this.form.afEffectMonth = this.form.afEffectMonth +'-01';
          }
          if(this.form.handleInsuranceType){
            this.form.handleInsuranceType = this.form.handleInsuranceType.sort();
            this.form.handleInsuranceType = this.form.handleInsuranceType.toString();
          }
          if (this.form.id != null) {
            updatePeopleSsafReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPeopleSsafReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除员工社保公积金申报编号为"' + ids + '"的数据项？').then(function () {
        return delPeopleSsafReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('peopleSsafReport/peopleSsafReport/export', {
        ...this.queryParams
      }, `report_${new Date().getTime()}.xlsx`)
    },

    /** 提交至申报*/
    handleSubmit(row){
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认提交至申报编号为"' + ids + '"的数据项？').then(function () {
        return submitToReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("提交成功");
      }).catch(() => {
      });
    },
    /** 申报成功 */
    handleComplete(row) {

    },
    /** 申报失败 */
    handleFail(row) {

    },

    /** 根据员工编号查询*/
    queryPeopleByCode(code) {
      queryByCode(code).then(res => {
        if (res.code === 200) {
          this.form.peopleId = res.data.id;
          this.form.peopleName = res.data.name;
          this.form.peopleCode = res.data.code;
          this.form.companyNameSecond = res.data.company.nameSecond;
          this.form.socialSecurityNum = res.data.socialSecurityNum;
          this.form.fundNum = res.data.fundNum;
          this.form.ssPayProportion = "养老：企业" + res.data.signMain.yangLaoPayProportionEtp
            + "%个人" + res.data.signMain.yangLaoPayProportionPsn + "%；" +
            "医疗：企业" + res.data.signMain.yiLiaoPayProportionEtp
            + "%个人" + res.data.signMain.yiLiaoPayProportionPsn + "%；" +
            "失业：企业" + res.data.signMain.shiYePayProportionEtp
            + "%个人" + res.data.signMain.shiYePayProportionPsn + "%；" +
            "工伤" + res.data.signMain.gongShangPayProportionEtp
            + "%；生育" + res.data.signMain.shengYuPayProportionEtp + "%"
          ;
          if(res.data.signMain.afPayProportionEtp){
            this.form.afPayProportion = "企业" + res.data.signMain.afPayProportionEtp + "%，个人" + res.data.signMain.afPayProportionPsn + "%";
          }        }
      }).catch(() => {
        this.form.peopleId = null;
        this.form.peopleName = null;
        this.form.peopleCode = null;
        this.form.companyNameSecond = null;
        this.form.ssPayProportion = null;
        this.form.afPayProportion = null;
        this.form.socialSecurityNum = null;
        this.form.fundNum = null;
      })
    },

    /**社保办理险种格式化*/
    handleInsuranceTypeFormat(row) {
      var str = ''
      if (row.handleInsuranceType) {
        var type = row.handleInsuranceType.split(",");
        if (type.length > 0) {
          for (var item of type) {
            switch (item) {
              case '1':
                str += '养老,'
                break;
              case '2':
                str += '医疗,'
                break;
              case '3':
                str += '失业,'
                break;
              case '4':
                str += '工伤,'
                break;
              case '5':
                str += '生育,'
                break;
              default:
                break;
            }
          }
        }
        return str.substring(0, str.length - 1)
      }
      return str;
    },
    /** 限制正整数*/
    validateAfMonthNum(value) {
      this.form.afSupplementMonthNum = /^[0-9]*$/.test(parseInt(value)) ? String(parseInt(value)).replace(".", "") : ""
    },
    validateSsMonthNum(value){
      this.form.ssSupplementMonthNum = /^[0-9]*$/.test(parseInt(value))? String(parseInt(value)).replace(".", "") : ""
    },
    /**
     * 获取省
     */
    getProvince() {
      getChildrenById(0).then(res => {
        if (res.code === 200){
          this.provinceOptions = res.data;
        }
      })
    },
    /**获取对应的市*/
    getCity(value) {
      getChildrenById(value).then(res => {
        if (res.code === 200){
          this.cityOptions = res.data;
        }
      })
    },
    /** 导入*/
    handleImport(){
      this.upload.title = "员工社保申报导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('peopleSsafReport/peopleSsafReport/importTemplate', {}, `peopleSsafReport_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.upload.updateSupport = 0;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 100vh;padding: 10px 10px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

  }
};
</script>
